/*
 * 
 */
package fr.univtln.superplanning.api.event;

import static javax.persistence.InheritanceType.JOINED;

import java.util.Calendar;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

// TODO: Auto-generated Javadoc
/**
 * This abstract class represents an event.
 * 
 * @author vincent
 * 
 */
@Entity
@Inheritance(strategy = JOINED)
public abstract class Event implements IEvent {

	/** The id. */
	@Id
	@GeneratedValue
	private long id;

	/** The begin date time. */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false)
	private Calendar beginDateTime;

	/** The duration is in minutes */
	@Column(nullable = false)
	private int duration;

	/** The comments. */
	private String comments;

	/** The type. */
	// TODO: in the future, change to false
	@JoinColumn(nullable = true)
	@ManyToOne(cascade = CascadeType.ALL)
	private EventType type;

	/**
	 * Instantiates a new event.
	 */
	public Event() {
		// TODO Auto-generated constructor stub
	}

	public Event(Calendar beginDateTime, int duration, String comments, EventType type) {
		super();
		this.beginDateTime = beginDateTime;
		this.duration = duration;
		this.comments = comments;
		this.type = type;
	}

	/**
	 * Instantiates a new event.
	 * 
	 * @param beginDateTime
	 *            the begin date time
	 * @param endDateTime
	 *            the end date time
	 * @param type
	 *            the type
	 * @param comments
	 *            the comments
	 */
	public Event(Calendar beginDateTime, int duration, EventType type, String comments) {
		this(beginDateTime, duration, type);
		this.comments = comments;
	}

	/**
	 * Instantiates a new event.
	 * 
	 * @param beginDateTime
	 *            the begin date time
	 * @param endDateTime
	 *            the end date time
	 * @param type
	 *            the type
	 */
	public Event(Calendar beginDateTime, int duration, EventType type) {
		super();
		this.beginDateTime = beginDateTime;
		this.duration = duration;
		this.type = type;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see fr.univtln.superplanning.api.event.IEvent#getBeginDateTime()
	 */
	public Calendar getBeginDateTime() {
		return beginDateTime;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * fr.univtln.superplanning.api.event.IEvent#setBeginDateTime(java.util.
	 * Calendar)
	 */
	public void setBeginDateTime(Calendar beginDateTime) {
		this.beginDateTime = beginDateTime;
	}

	public int getDuration() {
		return duration;
	}

	public void setDuration(int duration) {
		this.duration = duration;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see fr.univtln.superplanning.api.event.IEvent#getComments()
	 */
	public String getComments() {
		return comments;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * fr.univtln.superplanning.api.event.IEvent#setComments(java.lang.String)
	 */
	public void setComments(String comments) {
		this.comments = comments;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see fr.univtln.superplanning.api.event.IEvent#getType()
	 */
	public EventType getType() {
		return type;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * fr.univtln.superplanning.api.event.IEvent#setType(fr.univtln.superplanning
	 * .api.event.EventType)
	 */
	public void setType(EventType type) {
		this.type = type;
	}

	/**
	 * Gets the id.
	 * 
	 * @return the id
	 */
	public long getId() {
		return id;
	}

	@Override
	public String toString() {
		return "Event [beginDateTime=" + beginDateTime + ", duration=" + duration + ", comments="
				+ comments + ", type=" + type + "]";
	}

}
